<?php

class Core_Template_Html_Form_Editor extends Soul_Template_Html_Form_Textarea {

    private $_theme = 'advanced';
	
    public function __construct() {
        parent::__construct();
        $this->templateName = 'form/editor';
    }
    
    public function getTheme(){
    	return $this->_theme;
    }
    
    public function setTheme($value){
    	$this->_theme = $value;
    	return $this;
    }

    protected function renderEditable() {   	
    	$scriptUrl = BL.'pub/skin/share/js/tinymce/';
    	$res = Soul_Template_Resource::getInstance()
    				->addReferenceScript('tinymce', $scriptUrl.'tiny_mce.js')
    				->addReferenceScript('jquerytinymce', $scriptUrl.'jquery.tinymce.js');
    	$script = "jQuery('#".$this->getId()."').tinymce({"
    			. 'language : "zh-cn",'
    			. 'height: 400,'
                . 'theme:"'.$this->getTheme().'"';
        if($this->getTheme() == 'advanced'){
        	$script .= ',plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",'
					. 'theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontsizeselect",'
					. 'theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,|,forecolor,backcolor",'
					. 'theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,advhr,|,ltr,rtl,|,pagebreak",'
					. 'theme_advanced_resizing : true,'
					. 'theme_advanced_toolbar_location : "top",'
        			. 'theme_advanced_toolbar_align : "left",';					
		}
		$script .= '});';
    	$res->addStartupScript($script);
        return parent::renderEditable();
    }

    public function getType() {
        return 'editor';
    }

}